﻿<UserControl x:Class="DemoNYTimes.MovieReviewsPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"  
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:local="clr-namespace:DemoNYTimes"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:nyt="clr-namespace:NYTimes;assembly=NYTimesSilverlightKit"           
    xmlns:nytvc="clr-namespace:NYTimes.ValueConverters;assembly=NYTimesSilverlightKit"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    d:DesignWidth="640" d:DesignHeight="480"
    FontFamily="Times New Roman" FontSize="12" mc:Ignorable="d" Background="#FFFFFFFF">
    <UserControl.Resources>
    	<nyt:MovieReviewsByKeyword x:Key="MovieReviews" d:IsDataSource="True"/>
		<nytvc:VisibleIfTrueConverter x:Key="VisibleIfTrueConverterDS" d:IsDataSource="True"/>
        <nytvc:CollapsedIfNullConverter x:Key="CollapsedIfNullConverterDS" d:IsDataSource="True"/>
        <nytvc:CriticToReviewerDetailsConverter x:Key="CriticToReviewerDetailsConverter" 
                                                d:IsDataSource="True"/>
        <Style x:Key="TextBlockStyle" TargetType="TextBlock">
            <Setter Property="FontSize" Value="14"/>
        </Style>
        <DataTemplate x:Key="MovieTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="81"/>
                    <ColumnDefinition Width="Auto" MinWidth="434"/>
                    <ColumnDefinition Width="Auto" MinWidth="90"/>
                </Grid.ColumnDefinitions>
                <Image VerticalAlignment="Top" Margin="2,2,2,0" Source="{Binding Path=Thumbnail}" Stretch="Uniform" ImageFailed="OnImageFailed">
                    <Image.Clip>
                        <RectangleGeometry RadiusX="8" RadiusY="8" Rect="0,0,75,75"/>
                    </Image.Clip>
                </Image>
                <StackPanel Grid.Column="1" Margin="2,2,-8,2" >
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource TextBlockStyle}" 
                                   Text="{Binding Path=DisplayTitle}"/>
                        <TextBlock Style="{StaticResource TextBlockStyle}" Text=" ("/>
                        <TextBlock Style="{StaticResource TextBlockStyle}" 
                                   Text="{Binding Path=OpeningDate.Year}"/>
                        <TextBlock Style="{StaticResource TextBlockStyle}" Text=")"/>
                    </StackPanel>
                    <TextBlock Style="{StaticResource TextBlockStyle}" FontSize="16" 
                               FontWeight="Bold" Text="{Binding Path=Headline}"/>
                    <controls:Expander HorizontalAlignment="Left">
                        <controls:Expander.Header>
                            <StackPanel Height="Auto" Width="Auto" Orientation="Horizontal">
                                <TextBlock Style="{StaticResource TextBlockStyle}" Text="by " 
                                           TextWrapping="Wrap"/>
                                <TextBlock Height="Auto" Style="{StaticResource TextBlockStyle}" 
                                           Width="Auto" Text="{Binding Mode=OneWay, Path=Byline}" 
                                           TextWrapping="Wrap"/>
                            </StackPanel>
                        </controls:Expander.Header>
                        <local:CriticControl 
                            DataContext="{Binding Byline, Converter={StaticResource CriticToReviewerDetailsConverter}}"/>
                    </controls:Expander>
                    <TextBlock HorizontalAlignment="Left" MaxWidth="500" FontStyle="Italic" 
                        Style="{StaticResource TextBlockStyle}" Text="{Binding Path=CapsuleReview}" 
                               TextWrapping="Wrap"/>
                    <TextBlock HorizontalAlignment="Left" MaxWidth="500" Style="{StaticResource TextBlockStyle}" 
                               Text="{Binding Path=SummaryShort}" TextWrapping="Wrap"/>
                	<HyperlinkButton Content="{Binding Mode=OneWay, Path=Link.SuggestedLinkText}" 
                               NavigateUri="{Binding Mode=OneWay, Path=Link.Url}" 
                               TargetName="_blank" Padding="0,0,2,0"/>
                </StackPanel>
                <StackPanel Height="Auto" Grid.Column="2" Margin="10,0,0,0">
                    <Border HorizontalAlignment="Right" Margin="2,2,2,2" BorderBrush="#FF000000" 
                            BorderThickness="1,1,1,1" Padding="2,2,2,2" 
                            Visibility="{Binding MPAARating, Converter={StaticResource CollapsedIfNullConverterDS} }">
                        <TextBlock x:Name="MPAARating" FontFamily="Times New Roman" FontSize="20" 
                                   Foreground="#FF000000" 
                                   Text="{Binding Mode=OneWay, Path=MPAARating}" 
                                   TextWrapping="NoWrap" FontWeight="Bold"/>
                    </Border>
                    <TextBlock x:Name="CriticsPick" Opacity="1" RenderTransformOrigin="0,1" 
                               FontFamily="Trebuchet MS" FontWeight="Bold" Foreground="#FF0014C7" 
                               Text="Critic's Pick" TextWrapping="NoWrap" 
                               Visibility="{Binding Converter={StaticResource VisibleIfTrueConverterDS}, Path=CriticsPick}" 
                               ToolTipService.ToolTip="A New York Times Critics' Pick" 
                               TextAlignment="Right"/>
                	<TextBlock Text="Thousand Best" TextWrapping="NoWrap" x:Name="ThousandBest" 
                               FontFamily="Trebuchet MS" FontWeight="Bold" 
                               Visibility="{Binding Converter={StaticResource VisibleIfTrueConverterDS}, Path=ThousandBest}" 
                               Foreground="#FFFF0000" TextAlignment="Right" 
                               ToolTipService.ToolTip="This movie is included in the The New York list of the best 1,000 movies ever made."/>
                    <controls:Expander Header="Links">
                        <ListBox ItemsSource="{Binding RelatedUrls}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <HyperlinkButton 
                                        Content="{Binding SuggestedLinkText}" NavigateUri="{Binding Url}" 
                                        TargetName="_blank"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </controls:Expander>
                </StackPanel>
            </Grid>
        </DataTemplate>
        <Style x:Key="ListBoxStyle1" TargetType="ListBox">
        	<Setter Property="Padding" Value="1"/>
        	<Setter Property="Background" Value="#FFFFFFFF"/>
        	<Setter Property="Foreground" Value="#FF000000"/>
        	<Setter Property="HorizontalContentAlignment" Value="Left"/>
        	<Setter Property="VerticalContentAlignment" Value="Top"/>
        	<Setter Property="IsTabStop" Value="False"/>
        	<Setter Property="BorderThickness" Value="1"/>
        	<Setter Property="TabNavigation" Value="Once"/>
        	<Setter Property="BorderBrush">
        		<Setter.Value>
        			<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
        				<GradientStop Color="#FFA3AEB9" Offset="0"/>
        				<GradientStop Color="#FF8399A9" Offset="0.375"/>
        				<GradientStop Color="#FF718597" Offset="0.375"/>
        				<GradientStop Color="#FF617584" Offset="1"/>
        			</LinearGradientBrush>
        		</Setter.Value>
        	</Setter>
        	<Setter Property="Template">
        		<Setter.Value>
        			<ControlTemplate TargetType="ListBox">
        				<Border BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                CornerRadius="2">
        					<ScrollViewer x:Name="ScrollViewer" 
                                          Background="{TemplateBinding Background}" 
                                          BorderBrush="Transparent" BorderThickness="0" 
                                          Padding="{TemplateBinding Padding}" 
                                          HorizontalContentAlignment="Stretch">
        						<ItemsPresenter/>
        					</ScrollViewer>
        				</Border>
        			</ControlTemplate>
        		</Setter.Value>
        	</Setter>
        </Style>
        <ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
        	<StackPanel HorizontalAlignment="Stretch"/>
        </ItemsPanelTemplate>
    	
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="#FFFFFFFF">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <TextBox Text="{Binding Mode=TwoWay, Path=Query, Source={StaticResource MovieReviews}}" 
                 Margin="2,2,2,2" KeyDown="OnQueryKeyDown"/>
        <StackPanel Grid.Column="1" Orientation="Horizontal" Margin="2,2,2,2">
            <TextBlock Style="{StaticResource TextBlockStyle}" 
                       Text="{Binding Path=Results.Count, Source={StaticResource MovieReviews}}" 
                       VerticalAlignment="Center"/>
            <TextBlock Style="{StaticResource TextBlockStyle}" Text="/" 
                       VerticalAlignment="Center"/>
            <TextBlock Style="{StaticResource TextBlockStyle}" 
                       Text="{Binding Path=TotalResults, Source={StaticResource MovieReviews}}" 
                       VerticalAlignment="Center"/>
        </StackPanel>
        <ListBox Grid.Row="1" Grid.ColumnSpan="2" ItemTemplate="{StaticResource MovieTemplate}" 
                 ItemsSource="{Binding Path=Results, Source={StaticResource MovieReviews}}" 
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled" Margin="2,2,2,2" 
                 Style="{StaticResource ListBoxStyle1}" HorizontalAlignment="Stretch" 
                 HorizontalContentAlignment="Stretch" 
                 ItemsPanel="{StaticResource ItemsPanelTemplate1}" />
        <TextBlock Style="{StaticResource TextBlockStyle}" Grid.Row="2" 
                   Text="{Binding Path=Copyright, Source={StaticResource MovieReviews}}" 
                   Margin="2,2,2,2"/>
    </Grid>
</UserControl>
